/**
 * 项目表单配置模块
 * 用于集中管理项目表单的字段定义和逻辑配置
 */

/**
 * 获取项目表单配置
 * @param {string} type 项目类型
 * @returns {object} 表单配置
 */
function getFormConfigByType(type) {
  // 根据类型返回不同的表单配置
  switch (type) {
    case '磁编':
    case '霍尔':
      return getMagneticEncoderFormConfig();
    case '吸尘器':
      return getVacuumCleanerFormConfig();
    case '风扇':
      return getFanFormConfig();
    case '按摩椅':
      return getMassageChairFormConfig();
    default:
      return getDefaultFormConfig();
  }
}

/**
 * 磁编/霍尔项目表单配置
 * @returns {object} 表单配置
 */
function getMagneticEncoderFormConfig() {
  return {
    // 基础信息参数
    basicParams: [
      {
        name: 'model',
        label: '项目型号',
        type: 'text',
        placeholder: '请输入项目型号',
        required: true
      },
      {
        name: 'customerName',
        label: '客户名称',
        type: 'text',
        placeholder: '请输入客户名称',
        required: true
      },
      {
        name: 'description',
        label: '项目描述',
        type: 'textarea',
        placeholder: '请输入项目描述',
        required: false
      },
      {
        name: 'projectLead',
        label: '项目负责人',
        type: 'text',
        placeholder: '请输入项目负责人',
        required: false
      },
      {
        name: 'salespersonName',
        label: '销售负责人',
        type: 'text',
        placeholder: '请输入销售负责人',
        required: false
      },
      {
        name: 'startDate',
        label: '开始日期',
        type: 'date',
        required: true
      },
      {
        name: 'deadline',
        label: '截止日期',
        type: 'date',
        required: true
      },
      {
        name: 'priority',
        label: '优先级',
        type: 'select',
        options: ['低', '中', '高'],
        required: true
      },
      {
        name: 'hasSample',
        label: '是否有样品',
        type: 'select',
        options: ['无', '有'],
        required: true
      }
    ],
    
    // 样品参数，当hasSample为'有'时显示
    sampleParams: [
      {
        name: 'sampleCount',
        label: '样品数量',
        type: 'text',
        placeholder: '请输入样品数量',
        required: true,
        validation: 'number'
      },
      {
        name: 'sampleImages',
        label: '样品图片',
        type: 'image',
        max: 3,
        required: false
      }
    ]
  };
}

/**
 * 吸尘器项目表单配置
 * @returns {object} 表单配置
 */
function getVacuumCleanerFormConfig() {
  return {
    // 基础信息参数
    basicParams: [
      {
        name: 'model',
        label: '项目型号',
        type: 'text',
        placeholder: '请输入项目型号',
        required: true
      },
      {
        name: 'customerName',
        label: '客户名称',
        type: 'text',
        placeholder: '请输入客户名称',
        required: true
      },
      {
        name: 'description',
        label: '项目描述',
        type: 'textarea',
        placeholder: '请输入项目描述',
        required: false
      },
      {
        name: 'projectLead',
        label: '项目负责人',
        type: 'text',
        placeholder: '请输入项目负责人',
        required: false
      },
      {
        name: 'salespersonName',
        label: '销售负责人',
        type: 'text',
        placeholder: '请输入销售负责人',
        required: false
      },
      {
        name: 'startDate',
        label: '开始日期',
        type: 'date',
        required: true
      },
      {
        name: 'deadline',
        label: '截止日期',
        type: 'date',
        required: true
      },
      {
        name: 'priority',
        label: '优先级',
        type: 'select',
        options: ['低', '中', '高'],
        required: true
      },
      {
        name: 'hasSample',
        label: '是否有样品',
        type: 'select',
        options: ['无', '有'],
        required: true
      }
    ],
    
    // 样品参数，当hasSample为'有'时显示
    sampleParams: [
      {
        name: 'sampleCount',
        label: '样品数量',
        type: 'text',
        placeholder: '请输入样品数量',
        required: true,
        validation: 'number'
      },
      {
        name: 'sampleImages',
        label: '样品图片',
        type: 'image',
        max: 3,
        required: false
      }
    ],
    
    // 基本参数
    baseParams: [
      {
        name: 'applicationType',
        label: '应用场景',
        type: 'select',
        options: ['家用', '商用', '工业用'],
        required: true
      },
      {
        name: 'workTemp',
        label: '工作温度(℃)',
        type: 'text',
        placeholder: '例如：0~70',
        required: true
      },
      {
        name: 'certification',
        label: '认证要求',
        type: 'select',
        options: ['无', 'CE', 'UL', 'CCC', 'CE/ROHS', '其他'],
        required: true
      }
    ],
    
    // 电源参数
    powerParams: [
      {
        name: 'ratedVoltage',
        label: '额定电压(V)',
        type: 'text',
        placeholder: '例如：10.8',
        required: true,
        validation: 'number'
      },
      {
        name: 'maxPower',
        label: '最大功率(W)',
        type: 'text',
        placeholder: '例如：120',
        required: true,
        validation: 'number'
      },
      {
        name: 'lowPower',
        label: '待机功率(W)',
        type: 'text',
        placeholder: '例如：0',
        required: true,
        validation: 'number'
      },
      {
        name: 'startupTime',
        label: '启动时间(s)',
        type: 'text',
        placeholder: '例如：1',
        required: true,
        validation: 'number'
      }
    ],
    
    // 电机参数
    motorParams: [
      {
        name: 'maxSpeed',
        label: '最高转速(RPM)',
        type: 'text',
        placeholder: '例如：110000',
        required: true,
        validation: 'number'
      },
      {
        name: 'polePairs',
        label: '极对数',
        type: 'text',
        placeholder: '例如：1',
        required: true,
        validation: 'number'
      },
      {
        name: 'hasHall',
        label: '霍尔传感器',
        type: 'select',
        options: ['无', '有'],
        required: true
      },
      {
        name: 'hasFG',
        label: 'FG信号',
        type: 'select',
        options: ['无', '有'],
        required: true
      },
      {
        name: 'conformalCoating',
        label: '三防漆',
        type: 'select',
        options: ['无', '有'],
        required: true
      },
      {
        name: 'hasBrake',
        label: '制动功能',
        type: 'select',
        options: ['无', '有'],
        required: true
      }
    ],
    
    // 控制部分
    controlParams: [
      {
        name: 'controlMode',
        label: '控制方式',
        type: 'select',
        options: ['恒速', '恒功率', '恒转矩'],
        required: true
      },
      {
        name: 'controlAlgorithm',
        label: '控制算法',
        type: 'select',
        options: ['FOC', 'BLDC', '其他'],
        required: true
      },
      {
        name: 'rotation',
        label: '转向',
        type: 'select',
        options: ['正转', '反转', '无'],
        required: true
      },
      {
        name: 'controlInterface',
        label: '控制接口',
        type: 'select',
        options: ['按键控制', 'PWM控制', 'VSP控制', '数字通信', '其他'],
        required: true
      },
      {
        name: 'controlDescription',
        label: '控制详细描述',
        type: 'textarea',
        placeholder: '请输入控制详细描述',
        required: false
      }
    ],
    
    // PWM控制子参数
    pwmControlParams: [
      {
        name: 'pwmStartDuty',
        label: '启动占空比(%)',
        type: 'text',
        placeholder: '例如：10',
        required: true,
        validation: 'number'
      },
      {
        name: 'pwmStopDuty',
        label: '停止占空比(%)',
        type: 'text',
        placeholder: '例如：8',
        required: true,
        validation: 'number'
      },
      {
        name: 'pwmDutyRange',
        label: '占空比范围(%)',
        type: 'text',
        placeholder: '例如：10～90',
        required: true
      },
      {
        name: 'pwmFreqRange',
        label: '频率范围(kHz)',
        type: 'text',
        placeholder: '例如：1～10',
        required: true
      }
    ],
    
    // VSP控制子参数
    vspControlParams: [
      {
        name: 'vspStartVoltage',
        label: '启动电压(V)',
        type: 'text',
        placeholder: '例如：1.0',
        required: true,
        validation: 'number'
      },
      {
        name: 'vspStopVoltage',
        label: '停止电压(V)',
        type: 'text',
        placeholder: '例如：0.8',
        required: true,
        validation: 'number'
      },
      {
        name: 'vspVoltageRange',
        label: '电压范围(V)',
        type: 'text',
        placeholder: '例如：1.0～4.5',
        required: true
      }
    ],
    
    // 保护部分
    protectionParams: [
      {
        name: 'stallProtection',
        label: '堵转保护',
        type: 'select',
        options: ['无', '有，自恢复', '有，手动重开', '有，仅断电重启'],
        required: true
      },
      {
        name: 'blockageProtection',
        label: '堵塞保护',
        type: 'select',
        options: ['无', '有'],
        required: true
      },
      {
        name: 'phaseProtection',
        label: '缺相保护',
        type: 'select',
        options: ['无', '有，自恢复', '有，手动重开', '有，仅断电重启'],
        required: true
      },
      {
        name: 'overvoltageProtection',
        label: '过压保护',
        type: 'select',
        options: ['无', '有，自恢复', '有，手动重开', '有，仅断电重启'],
        required: true
      },
      {
        name: 'undervoltageProtection',
        label: '欠压保护',
        type: 'select',
        options: ['无', '有，自恢复', '有，手动重开', '有，仅断电重启'],
        required: true
      },
      {
        name: 'temperatureProtection',
        label: '温度保护',
        type: 'select',
        options: ['无', '有，自恢复', '有，手动重开', '有，仅断电重启'],
        required: true
      },
      {
        name: 'overcurrentProtection',
        label: '过流保护',
        type: 'select',
        options: ['无', '有，自恢复', '有，手动重开', '有，仅断电重启'],
        required: true
      },
      {
        name: 'currentLimitProtection',
        label: '电流限制保护',
        type: 'select',
        options: ['无', '有'],
        required: true
      }
    ],
    
    // 堵转保护子参数
    stallProtectionParams: [
      {
        name: 'stallHoldTime',
        label: '堵转保持时间(s)',
        type: 'text',
        placeholder: '例如：1',
        required: true,
        validation: 'number'
      }
    ],
    
    // 堵转保护-自恢复子参数
    stallAutoRecoveryParams: [
      {
        name: 'stallRestartTime',
        label: '堵转重启时间(s)',
        type: 'text',
        placeholder: '例如：1',
        required: true,
        validation: 'number'
      },
      {
        name: 'stallRestartCount',
        label: '堵转重启次数',
        type: 'text',
        placeholder: '例如：1',
        required: true,
        validation: 'number'
      }
    ],
    
    // 过压保护子参数
    overvoltageParams: [
      {
        name: 'overvoltageValue',
        label: '过压保护值(V)',
        type: 'text',
        placeholder: '例如：15',
        required: true,
        validation: 'number'
      }
    ],
    
    // 过压保护-自恢复子参数
    overvoltageAutoRecoveryParams: [
      {
        name: 'overvoltageRecoveryValue',
        label: '过压恢复值(V)',
        type: 'text',
        placeholder: '例如：14',
        required: true,
        validation: 'number'
      }
    ],
    
    // 欠压保护子参数
    undervoltageParams: [
      {
        name: 'undervoltageValue',
        label: '欠压保护值(V)',
        type: 'text',
        placeholder: '例如：6',
        required: true,
        validation: 'number'
      }
    ],
    
    // 欠压保护-自恢复子参数
    undervoltageAutoRecoveryParams: [
      {
        name: 'undervoltageRecoveryValue',
        label: '欠压恢复值(V)',
        type: 'text',
        placeholder: '例如：6.5',
        required: true,
        validation: 'number'
      }
    ],
    
    // 温度保护子参数
    temperatureParams: [
      {
        name: 'protectionTemp',
        label: '保护温度(°C)',
        type: 'text',
        placeholder: '例如：90',
        required: true,
        validation: 'number'
      }
    ],
    
    // 温度保护-自恢复子参数
    temperatureAutoRecoveryParams: [
      {
        name: 'recoveryTemp',
        label: '恢复温度(°C)',
        type: 'text',
        placeholder: '例如：80',
        required: true,
        validation: 'number'
      }
    ],
    
    // 过流保护子参数
    overcurrentParams: [
      {
        name: 'overcurrentValue',
        label: '过流保护值(A)',
        type: 'text',
        placeholder: '例如：30',
        required: true,
        validation: 'number'
      }
    ],
    
    // 电流限制保护子参数
    currentLimitParams: [
      {
        name: 'currentLimitValue',
        label: '电流限制值(A)',
        type: 'text',
        placeholder: '例如：12',
        required: true,
        validation: 'number'
      }
    ],
    
    // 堵塞保护子参数
    blockageParams: [
      {
        name: 'blockageDiameter',
        label: '堵塞直径(mm)',
        type: 'text',
        placeholder: '例如：3',
        required: true,
        validation: 'number'
      },
      {
        name: 'blockageHoldTime',
        label: '堵塞保持时间(s)',
        type: 'text',
        placeholder: '例如：5',
        required: true,
        validation: 'number'
      }
    ]
  };
}

/**
 * 风扇项目表单配置
 * @returns {object} 表单配置
 */
function getFanFormConfig() {
  // 基于吸尘器配置修改
  const config = getVacuumCleanerFormConfig();
  
  // 添加风扇特有参数
  config.fanSpecificParams = [
    {
      name: 'fanDiameter',
      label: '风扇直径(mm)',
      type: 'text',
      placeholder: '例如：120',
      required: true,
      validation: 'number'
    },
    {
      name: 'airVolume',
      label: '风量(m³/min)',
      type: 'text',
      placeholder: '例如：2.1',
      required: true,
      validation: 'number'
    },
    {
      name: 'noiseLevel',
      label: '噪音等级(dB)',
      type: 'text',
      placeholder: '例如：45',
      required: true,
      validation: 'number'
    }
  ];
  
  return config;
}

/**
 * 按摩椅项目表单配置
 * @returns {object} 表单配置
 */
function getMassageChairFormConfig() {
  // 基于吸尘器配置修改
  const config = getVacuumCleanerFormConfig();
  
  // 添加按摩椅特有参数
  config.chairSpecificParams = [
    {
      name: 'massageType',
      label: '按摩类型',
      type: 'select',
      options: ['揉捏', '敲打', '推拿', '综合'],
      required: true
    },
    {
      name: 'chairWidth',
      label: '椅宽(mm)',
      type: 'text',
      placeholder: '例如：650',
      required: true,
      validation: 'number'
    },
    {
      name: 'chairWeight',
      label: '椅重(kg)',
      type: 'text',
      placeholder: '例如：85',
      required: true,
      validation: 'number'
    }
  ];
  
  return config;
}

/**
 * 默认项目表单配置
 * @returns {object} 表单配置
 */
function getDefaultFormConfig() {
  return getMagneticEncoderFormConfig();
}

module.exports = {
  getFormConfigByType,
  getVacuumCleanerFormConfig,
  getFanFormConfig,
  getMassageChairFormConfig,
  getMagneticEncoderFormConfig,
  getDefaultFormConfig
}; 